﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace MapControl
{
    internal class CommonProjectionCalculator : IProjectionCalculator
    {
        private static Dictionary<int, GoogleMapsAPIProjection> projections = new Dictionary<int, GoogleMapsAPIProjection>();

        #region IProjectionCalculator Members

        public GeoFramework.Position FromPoint(GeoFramework.PointD p, int zoomLevel)
        {
            return GetProjection(zoomLevel).FromPixelToCoordinates(p);
        }

        public GeoFramework.PointD FromPosition(GeoFramework.Position p, int zoomLevel)
        {
            return GetProjection(zoomLevel).FromCoordinatesToPixel(p);
        }

        #endregion

        private static GoogleMapsAPIProjection GetProjection(int zoom)
        {
            if (!projections.ContainsKey(zoom))
                projections.Add(zoom, new GoogleMapsAPIProjection(zoom));
            return projections[zoom];
        }
    }
}
